package spring.webflux;

import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import spring.webflux.entity.Personnel;

public class Client {
    public static void main(String[] args) {
        WebClient webClient = WebClient.create("http://127.0.0.1:55936");

        Personnel personnel = webClient.get().uri("/personnel/{id}", 1).accept(MediaType.APPLICATION_JSON).retrieve()
                .bodyToMono(Personnel.class).block();
        System.out.println(personnel);

        Flux<Personnel> personnelFlux = webClient.get().uri("/personnel").accept(MediaType.APPLICATION_JSON).retrieve()
                .bodyToFlux(Personnel.class);
        personnelFlux.map(p -> p.getName()).buffer().doOnNext(System.out::println);
    }
}
